# conding = utf-8
import time
from selenium.webdriver import ActionChains, Keys
from pages.psx.SalesManager.SalesOrder import left_menu_management_order, left_menu_sales_order, find_order_id, \
    find_btn, \
    find_expected_id, find_order_product_news, find_expected_product_news, find_no_data_yet, \
    find_bnt_order_reset, find_order_date, find_oder_date_start_one, find_oder_date_end_one, \
    find_oder_date_start_two, find_oder_date_end_two, find_expected_date, \
    find_oder_date_year_one, find_oder_date_year_two, find_oder_date_mother_one, find_oder_date_mother_two, \
    find_customer, find_expected_customer, find_unfold, find_operator, find_expected_operator, find_expected_state, \
    find_state, find_oder_date_mother_three, find_remark, find_expected_remark, find_view, find_remark_close, \
    insert_order, insert_order_customer_txt, insert_order_customer, insert_order_barcodes, \
    insert_order_save, insert_order_next, insert_order_barcodes_bnt, insert_order_barcodes_null, \
    insert_order_barcodes_one, insert_order_line, insert_order_barcodes_two, insert_order_close, update_order, \
    update_order_customer, delete_order_one, delete_order_two, delete_order_txt, delete_order_sure_bnt, batch_checkbox, \
    batch_operation, batch_operation_opposite_audit, batch_operation_audit, batch_operation_state, \
    batch_operation_audit_sure, copy_order_bnt, view_order_in_id, view_order_bnt, delete_beach, view_order_colse, \
    delete_checkbox_two
from selenium.webdriver.common.by import By
from pages.page import Page

class SalesOrderPage(Page):
    '''
    销售管理->销售订单操作
    '''

    def open_sales_order(self):
        '''
        打开销售订单UI，如果已经打开则不会执行单击动作
        :return:
        '''
        if self.display(left_menu_sales_order) is False:  # 如果是隐藏状态则单击
            self.click(left_menu_management_order)
        self.click(left_menu_sales_order)

    #查询销售订单单据编号
    def search_input_id(self, value):
        '''
        输入查询数据，完成查询动作
        :param value:
        :return:
        '''
        self.send_keys(find_order_id, value)

    def search_btn(self):
        '''
        单击查找按钮
        :return:
        '''
        self.click(find_btn)

    def search_result_text_id(self):
        '''
        单击查找完成后，获取查找结果
        :return:
        '''
        return self.text(find_expected_id)

    def bnt_reset(self):
        '''
        输入框查询完成后，点击重置，以便输入下一个输入框
        :return:
        '''
        self.click(find_bnt_order_reset)

    def search_no_yet_txt(self):
        '''
        获取查询输入不存在
        :return:
        '''
        return self.text(find_no_data_yet)

    def search_reset(self):
        '''
        单击重置
        '''
        self.click(find_bnt_order_reset)

    # 查询销售订单商品信息
    def search_input_product_news(self, value):
        '''
        输入查询数据
        :param value:
        :return:
        '''
        self.send_keys(find_order_product_news, value)

    def search_result_text_product_news(self):
        '''
        单击查找完成后，获取查找结果
        :return:
        '''
        return self.text(find_expected_product_news)

    # 查询销售订单单据日期
    def search_input_date(self):
        '''
        点击查询输入框
        :param value:
        :return:
        '''
        self.click(find_order_date)

    def search_input_year_1(self):
        '''
        点击2024年份
        :param value:
        :return:
        '''
        self.click(find_oder_date_year_one)

    def search_input_year_2(self):
        '''
        点击2021年份
        :param value:
        :return:
        '''
        self.click(find_oder_date_year_two)

    def search_input_mother_1(self):
        '''
        点击月份
        :param value:
        :return:
        '''
        self.click(find_oder_date_mother_one)

    def search_input_mother_2(self):
        '''
        点击6月
        :param value:
        :return:
        '''
        self.click(find_oder_date_mother_two)

    def search_input_mother_3(self):
        '''
        点击12月
        :param value:
        :return:
        '''
        self.click(find_oder_date_mother_three)

    def search_input_date_start_one(self):
        '''
        点击开始日期
        :param value:
        :return:
        '''
        self.move_element(find_oder_date_start_one)

    def search_input_date_end_one(self):
        '''
        点击结束日期
        :param value:
        :return:
        '''
        self.move_element(find_oder_date_end_one)

    def search_input_date_start_two(self):
        '''
        点击开始日期
        :param value:
        :return:
        '''
        self.move_element(find_oder_date_start_two)

    def search_input_date_end_two(self):
        '''
        点击结束日期
        :param value:
        :return:
        '''
        self.move_element(find_oder_date_end_two)

    def search_date_enter(self):
        '''
        输入完回车
        '''
        actions = ActionChains(self.driver)  # 定义动作链
        actions.send_keys(Keys.ENTER)  # 回车键
        actions.perform()  # 执行动作链

    def search_result_text_date(self):
        '''
        单击查找完成后，获取查找结果
        :return:
        '''
        return self.text(find_expected_date)

    # 查询销售订单单据客户
    def search_unfold(self):
        '''
        点击展开
        '''
        self.click(find_unfold)

    def search_input_customer_one(self):
        '''
        点击查询输入框，输入客户3
        :param value:
        :return:
        '''
        self.click(find_customer)
        # 定义动作链
        actions = ActionChains(self.driver)
        # 右键
        actions.send_keys(Keys.RIGHT)
        time.sleep(1)
        # 回车键
        actions.send_keys(Keys.ENTER)
        # 执行动作链
        actions.perform()

    def search_input_customer_two(self):
        '''
        点击查询输入框，输入客户1
        :param value:
        :return:
        '''
        self.click(find_customer)
        # 定义动作链
        actions = ActionChains(self.driver)
        # 右键
        actions.send_keys(Keys.RIGHT)
        # 下键
        actions.send_keys(Keys.DOWN)
        actions.send_keys(Keys.RIGHT)
        actions.send_keys(Keys.DOWN)
        # 回车键
        actions.send_keys(Keys.ENTER)
        # 执行动作链
        actions.perform()

    def search_result_text_customer(self):
        '''
        单击查找完成后，获取查找结果
        :return:
        '''
        return self.text(find_expected_customer)

    # 查询销售订单单据操作员
    def search_input_operator_one(self):
        '''
        点击查询输入框，输入测试用户
        :param value:
        :return:
        '''
        self.click(find_operator)
        # 定义动作链
        actions = ActionChains(self.driver)
        # 右键
        actions.send_keys(Keys.RIGHT)
        # 回车键
        actions.send_keys(Keys.ENTER)
        # 执行动作链
        actions.perform()

    def search_input_operator_two(self):
        '''
        点击查询输入框，输入test123
        :param value:
        :return:
        '''
        self.click(find_operator)
        # 定义动作链
        actions = ActionChains(self.driver)
        # 右键
        actions.send_keys(Keys.RIGHT)
        # 下键
        actions.send_keys(Keys.DOWN)
        # 回车键
        actions.send_keys(Keys.ENTER)
        # 执行动作链
        actions.perform()

    def search_result_text_operator(self):
        '''
        单击查找完成后，获取查找结果
        :return:
        '''
        return self.text(find_expected_operator)

    # 查询销售订单单据状态
    def search_input_state_one(self):
        '''
        点击查询输入框，输入未审核
        :param value:
        :return:
        '''
        self.click(find_state)
        # 定义动作链
        actions = ActionChains(self.driver)
        # 右键
        actions.send_keys(Keys.RIGHT)
        # 回车键
        actions.send_keys(Keys.ENTER)
        # 执行动作链
        actions.perform()

    def search_input_state_two(self):
        '''
        点击查询输入框，输入完成销售
        :param value:
        :return:
        '''
        self.click(find_state)
        # 定义动作链
        actions = ActionChains(self.driver)
        # 右键
        actions.send_keys(Keys.RIGHT)
        # 下键
        actions.send_keys(Keys.DOWN)
        # 回车键
        actions.send_keys(Keys.RIGHT)
        actions.send_keys(Keys.DOWN)
        actions.send_keys(Keys.RIGHT)
        actions.send_keys(Keys.DOWN)
        actions.send_keys(Keys.ENTER)
        # 执行动作链
        actions.perform()

    def search_result_text_state(self):
        '''
        单击查找完成后，获取查找结果
        :return:
        '''
        return self.text(find_expected_state)

    # 查询销售订单备注
    def search_input_remark(self, value):
        '''
        输入查询数据，完成查询动作
        :param value:
        :return:
        '''
        self.send_keys(find_remark, value)

    def search_view(self):
        '''
        单击查看
        '''
        self.click(find_view)

    def search_result_text_remark(self):
        '''
        单击查找完成后，获取查找结果
        :return:
        '''
        return self.text(find_expected_remark)

    def search_remark_close(self):
        '''
        单击关闭查看页面
        '''
        self.click(find_remark_close)

    def increase_order_bnt(self):
        '''
        单击新增
        '''
        self.click(insert_order)

    def increase_order_customer_txt(self, value):
        '''
        客户文本框输入
        '''
        self.send_keys(insert_order_customer_txt, value)

    def fetch_table_line_one(self, insert_order_start_table):
        '''
        获取新增前表格行数
        '''
        return len(self.find_elements(eval(insert_order_start_table)))

    def increase_order_bnt(self):
        '''
        单击新增
        '''
        self.click(insert_order)

    def increase_order_next(self):
        '''
        判断下一步是否存在
        :return: 存在返回True,不存在返回False
        '''
        return self.is_exists(insert_order_next)

    def increase_order_next_count(self):
        '''
        获取存在个数
        '''
        return self.is_exists_count(insert_order_next)

    def increase_order_next_bnt(self):
        '''
        单击下一步
        '''
        self.click(insert_order_next)

    def increase_order_customer(self):
        '''
        输入客户1
        '''
        self.click(insert_order_customer)
        actions = ActionChains(self.driver)
        actions.send_keys(Keys.RIGHT)
        actions.send_keys(Keys.DOWN)
        actions.send_keys(Keys.RIGHT)
        actions.send_keys(Keys.DOWN)
        actions.send_keys(Keys.ENTER)
        actions.perform()

    def increase_order_barcodes_bnt_one(self):
        '''
        单击扫码输入按钮
        '''
        self.click(insert_order_barcodes_bnt)

    def increase_order_barcodes(self):
        '''
        输入条码
        '''
        self.click(insert_order_barcodes)
        time.sleep(1)
        actions = ActionChains(self.driver)
        actions.send_keys(Keys.NUMPAD1).send_keys(Keys.NUMPAD0).send_keys(Keys.NUMPAD1).send_keys(Keys.NUMPAD4).perform()
        time.sleep(1)
        actions.send_keys(Keys.ENTER)
        time.sleep(1)
        actions.perform()

    def increase_order_save(self):
        '''
        单击保存
        '''
        self.move_element(insert_order_save)

    def increase_order_customer_txt_null(self):
        '''
        获取客户为空的文本
        '''
        return self.text(insert_order_customer_txt)

    def increase_order_barcodes_txt(self):
        '''
        获取条码为空元素判断是否存在
        '''
        return self.is_exists(insert_order_barcodes_null)

    def increase_order_barcodes_hover(self):
        '''
        悬浮条码输入框
        '''
        self.move_element(insert_order_barcodes_one)

    def increase_order_barcodes_hover_one(self):
        '''
        悬浮插入行条码输入框
        '''
        self.move_element(insert_order_barcodes_two)

    def increase_order_line(self):
        '''
        单击插入行按钮
        '''
        self.click(insert_order_line)

    def increase_order_close(self):
        '''
        关闭新增页面
        '''
        self.click(insert_order_close)

    def revise_order(self):
        '''
        单击编辑按钮
        '''
        self.click(update_order)

    def revise_order_customer(self):
        '''
        输入客户2
        '''
        self.click(insert_order_customer)
        actions = ActionChains(self.driver)
        actions.send_keys(Keys.RIGHT)
        actions.send_keys(Keys.UP)
        actions.send_keys(Keys.ENTER)
        actions.perform()

    def revise_order_customer_txt(self):
        '''
        获取编辑成功断言
        '''
        return self.text(update_order_customer)

    def remove_order_one(self):
        '''
        单击删除1
        '''
        self.click(delete_order_one)

    def remove_order_two(self):
        '''
        单击删除1
        '''
        self.click(delete_order_two)

    def remove_order_sure_bnt(self):
        '''
        单击确认按钮
        '''
        self.move_element(delete_order_sure_bnt)

    def remove_order_txt(self):
        '''
        获取删除失败文本
        '''
        return self.text(delete_order_txt)

    def remove_table_line_one(self, delete_order_txt):
        '''
        获取删除后表格行数
        '''
        return len(self.find_elements(eval(delete_order_txt)))

    def review_checkbox(self):
        '''
        单击复选框
        '''
        self.click(batch_checkbox)

    def review_operation(self):
        '''
        悬浮单击批量操作
        '''
        self.move_element(batch_operation)

    def review_operation_opposite_audit(self):
        '''
        悬浮单击反审核
        '''
        self.move_element(batch_operation_opposite_audit)

    def review_operation_audit(self):
        '''
        悬浮单击审核
        '''
        self.move_element(batch_operation_audit)

    def review_operation_state(self):
        '''
        获取表格订单状态文本
        '''
        return self.text(batch_operation_state)

    def review_operation_audit_sure(self):
        '''
        单击审核反审核确认
        '''
        self.click(batch_operation_audit_sure)

    def replicate_order_bnt(self):
        '''
        单击复制
        '''
        self.click(copy_order_bnt)

    def check_order_bnt(self):
        '''
        单击查看
        '''
        self.click(view_order_bnt)

    def check_order_in_id(self):
        '''
        获取查看里编号
        '''
        return self.text(view_order_in_id)

    def check_order_close(self):
        '''
        关闭查看页面
        '''
        self.click(view_order_colse)

    def check_order_out_id(self, view_order_id):
        '''
        获取表格编号
        '''
        return self.text(eval(view_order_id))

    def replicate_order_bnt(self):
        '''
        单击复制
        '''
        self.click(copy_order_bnt)

    def replicate_table_line_one(self, copy_order_start_table):
        '''
        获取复制表格行
        '''
        return len(self.find_elements(eval(copy_order_start_table)))

    def delete_beach_bnt(self):
        '''
        鼠标悬浮单击批量删除
        '''
        self.move_element(delete_beach)

    def remove_checkbox_two(self):
        '''
        单击第三个复选框
        '''
        self.click(delete_checkbox_two)





